/*
 
 File:ECCommon.h
 Abstract:iPhone SDK extra class,including String,Date,File Access,UIKit,Algorithm
 
 Version:1.5
 
 Require
 Frameworks:none
 Classes:none
 
 Copyright 2009 ris shin. All rights reserved.
 
 */

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#define EC_DATE_TIME_FORMAT (@"yyyy-MM-dd HH:mm:ss")
#define EC_DATE_FORMAT (@"yyyy-MM-dd")
#define EC_TIME_FORMAT (@"HH:mm:ss")
#define EC_HOUR_FORMAT (@"HH")
#define EC_DATE_MONTH_DAY_FORMAT (@"MM-dd")
#define EC_CAST(CLASSNAME,OBJNAME) ((CLASSNAME *)OBJNAME)
#define EC_RELEASE_SAFELY(__POINTER) {[__POINTER RELEASE];__POINTER = nil;} 
#define EC_ALERT_TITLE @""

@interface ECCommon : NSObject {

}

#pragma mark -
#pragma mark NSString Extra
/*clear space through a given string */
+ (NSString *)sClearSpaceOfS:(NSString *)aString;

/*clear front space through a given string */
+ (NSString *)sClearFrontSpaceOfS:(NSString *)aString;

/*clear \n through a given string */
+ (NSString *)sClearNOfS:(NSString *)aString;

/*add enter at the end of a given string */
+ (NSString *)sAddEnterOfS:(NSString *)aString;

/*return a string build by 2 key words in the given string*/
+ (NSString *)sBetweenW1:(NSString *)w1 w2:(NSString *)w2 ofS:(NSString *)aString;

/*fill blank to the string to a certain length*/
+ (NSString *)sFillBlankOfS:(NSString *)aString length:(int)length;

/*split each word by multi space(without one space)*/
+ (NSMutableArray *)arrSplitMultiSpaceOfS:(NSString *)aString; //powerful

/*replace string of a given string */
+ (NSString *)sReplace:(NSString *)oriString toS:(NSString *)repString ofS:(NSString *)aString;

/*build string by index
   if startIndex is equal to -1 return the string from index 0 to endIndex,
   if endIndex is equal to -1 return the string from start index to the end.*/
+ (NSString *)sStartIndex:(int)startindex endIndex:(int)endindex ofS:(NSString *)aString;  

/*add quotation mark to a given string*/
+ (NSString *)sAddQuotationMarkOfS:(NSString *)aString;

/*return string from a int value*/
+ (NSString *)sOfI:(int)intValue;

/*give a split by thousand*/
+ (NSString *)sSplitByThousandOfS:(NSString *)aString;

/*reverse a string*/
+ (NSString *)sReverseOfS:(NSString *)aString;

/*add a separate to a given string e.g. 111,222,333*/
+ (NSString *)sAddSeparate:(NSString *)sepString byStep:(NSInteger)step ofS:(NSString *)aString;

/*string compare*/
+ (void)vStrCompareOfArr:(NSMutableArray *)aArray;

/*bool to string*/
+(NSString *)sOfBool:(bool)aBool;

#pragma mark -
#pragma mark NSDate Extra
/*convert string type to date type */
+ (NSDate *)dOfS:(NSString *)aString withFormat:(NSString *)format;

/*change a string time by a given timezone e.g.[NSTimeZone systemTimeZone]*/
+ (NSString *) sTimeByZoneOfS:(NSString *)aString timeZone:(NSTimeZone *)zone;

/*convert date type to string type*/
+ (NSString *)sOfD:(NSDate*)aDate withformat:(NSString *)format;

/*interconvert date type 31-Aug-2009 to date type 2009-08-31*/
+ (NSString *)sWordMiddleToAllNumberOfS:(NSString *)aString splitS:(NSString *)splitString;
+ (NSString *)sAllNumberToWordMiddleOfS:(NSString *)aString splitS:(NSString *)splitString;

/*intercovert Jan to 1*/
+ (NSString *)sMonthToNumberOfS:(NSString *)month;
+(NSString *)sNumberToMonthOfS:(NSString *)number;

/*get now date,time*/
+ (NSString *)sGetNowDate;
+ (NSString *)sGetNowTime;
+ (NSString *)sGetNowDateAndTime;

/*add year,month,day to date*/
+ (NSDate *)dAddYearOfD:(NSDate *)aDate months:(NSInteger)years;
+ (NSDate *)dAddMonthOfD:(NSDate *)aDate months:(NSInteger)months;
+ (NSDate *)dAddDayOfD:(NSDate *)aDate months:(NSInteger)days;

/*remove time from a NSDate*/
+ (NSDate *)dRemoveTimeOfD:(NSDate *)aDate;

#pragma mark -
#pragma mark File Access Extra
/*Serializable*/
+ (BOOL)bSaveToFileSerializable:(NSString *)fileName ofObj:(id)object;
+ (id)objLoadFromFile:(NSString *)fileName;

#pragma mark -
#pragma mark UIKit Extra
/*create navigation bar*/
+(void)vBarButtonWithTitle:(NSString *)title tar:(id)tar sel:(SEL)sel right:(BOOL)right ofNav:(UINavigationItem *)nav;

/*create alert view*/
+(void)vAlertWithTitle:(NSString *)title mes:(NSString *)mes del:(id)del cBtnTitle:(NSString *)cBtnTitle oBtnTitle:(NSString *)oBtnTitle tag:(NSInteger)tag;

/*rotating*/
+(CGRect)rectTransform90:(CGRect)rect;

#pragma mark -
#pragma mark Algorithm Extra
/*distinct the same number in the arry,ex.1,2,2,3,5 to 1,2,3,5*/
+(NSMutableArray  *)arrDistinct:(NSMutableArray  *)arr;

/*merge sort*/
+(void)vMergeSort:(NSMutableArray *)arr type:(NSString *)type;
+(void)vMerge_Sort:(NSMutableArray *)arr left:(int)left right:(int)right type:(NSString *)type;
+(void)vMerge:(NSMutableArray *)arr left:(int)left center:(int)center right:(int)right type:(NSString *)type;

/*get max value from array*/
+(int)iGetMAXValueFrom:(NSMutableArray *)arr;
+(float)fGetMAXValueFrom:(NSMutableArray *)arr;

/*binary search*/
+(int)iBinarySearch:(NSMutableArray *)arr date:(NSDate *)date;

@end
